//
//  UIButton+Extension.swift
//  iOSWeibo10
//
//  Created by itcast on 16/5/16.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(bkgImageName: String, imageName: String, title: String, titleColor: UIColor = UIColor.lightGrayColor(), fontSize: CGFloat = 12) {
        // 外面不传titleColor就使用默认的参数
        // 先调用当前类的指定或便利构造函数创建对象,创建完对象后给对象设置参数
        self.init(type: UIButtonType.Custom)
        // 设置
        self.setBackgroundImage(UIImage(named: bkgImageName), forState: UIControlState.Normal)
        self.setBackgroundImage(UIImage(named: "\(bkgImageName)_highlighted"), forState: UIControlState.Highlighted)
        
        self.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        self.setTitle(title, forState: UIControlState.Normal)
        self.setTitleColor(titleColor, forState: UIControlState.Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
}
